package org.jeecg.modules.yks.mqtt.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.yks.constant.EmqxManagerApi;
import org.jeecg.modules.yks.mqtt.service.MqttSubscriberService;
import org.jeecg.modules.yks.util.HttpConnectUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Dictionary;
import java.util.Hashtable;

/**
 * @author steven
 *
 * 2023-11-18
 */
@Slf4j
@Service
public class MqttSubscriberServiceImpl implements MqttSubscriberService {

    @Value("${mqtt.username}")
    private String username;

    @Value("${mqtt.pwd}")
    private String password;

    @Value("${mqtt.apiUrl}")
    private String hostUrl;

    @Value("${mqtt.apiPort}")
    private String port;

    private Dictionary<String,String> apiConfig = new Hashtable<>();

    private void initConfig(){
        apiConfig.put("username",username);
        apiConfig.put("password",password);
        apiConfig.put("hostUrl",hostUrl);
        apiConfig.put("port",port);
    }

    @Override
    public StringBuilder listAllSub() {
        initConfig();
        apiConfig.put("api", EmqxManagerApi.API_ESQM_ALL_SUBSCRIBER);
        return HttpConnectUtil.getData(apiConfig);
    }
}
